exp_name = 'ADL';

root = '../../_FGS/';

crank_root = 'classifier_output/crank/';

bag_root = 'classifier_output/bagging/';

temp_root = ['../' root crank_root];

feature_code = 'l';

crank_save_name = ['../crank_name_' exp_name '.txt'];

bag_save_name =  ['../bag_name_' exp_name '.txt'];

clear train_name;

%train_name{1} = 'GOPR2384_cab';

for i = 1:6
    train_name{i} = ['P_0' num2str(i)];
end


path = dir(temp_root);

count = 0;

clear prefixs
clear video_names

for k = 2:2%length(train_name)
    for i = 3:length(path)

        match_str = ['crank_' train_name{k} '_' feature_code ...
                    '_main.txt'];

        bag_match_str = ['bag_' match_str];

        fname = path(i).name;

        if(length(fname)< length(bag_match_str))
            continue;
        end

        if(~strcmp( fname(end- length(match_str)+1 : end),...
                    match_str ) )
            continue;
        end        

        if(~strcmp( fname(1:5), 'crank' ) )
            continue;
        end

        count = count +1;
        prefixs{count} = fname(1:end-length(match_str));
        sep = find(fname=='_');
        video_names{count} = train_name{k};        
    end    
end



fout = fopen(crank_save_name,'wt');

fprintf(fout,'%d\n',count);

for i = 1:count
    fprintf( fout ,'%s\n%s\n', prefixs{i},video_names{i});
end

fclose(fout);

temp_root = ['../' root bag_root];

path = dir(temp_root);

count = 0;

clear prefixs

for k = 1:length(train_name)
    for i = 3:length(path)
        match_str = ['_bag_' train_name{k} '_' feature_code ...
                    '_main.txt'];
                
        fname = path(i).name;
                
        if(length(fname)< length(match_str))
            continue;
        end

        if(~strcmp( fname(end- length(match_str)+1 : end),...
                    match_str ) )
            continue;
        end        

        count = count +1;
        sep = find(fname=='_');
        
        prefixs{count} = fname(sep(2)+1:sep(end-1)-1);
    end
end

fout = fopen(bag_save_name,'wt');

fprintf(fout,'%d\n',count);

for i = 1:count
    fprintf( fout ,'%s\n', prefixs{i});
end

fclose(fout);